<?php

namespace Controller\Article;

class Lists extends \Controller\Base {

    public function actionIndex() {
        $this->setMenuPath('Article', 'Lists');
        $pid = $this->getInt('pid');
        $categoryIds = array($pid);
        $pager = new \Lib\Core\Pager();
        $pager->pageSize = 20;
        $pager->currentPage = $this->getInt('page', 1);
        if ($pid) {
            $this->setMenuPath('Category_' . $pid, 'Article');

            $category = \Data\Category::instance()->getCategoryByPid($pid);
            foreach($category as $val) {
                $categoryIds[] = $val['CategoryId'];
            }
            $category = \Data\Category::instance()->getCategoryByIds($categoryIds);
            $articleInfo = \Business\Article::instance()->getAllArticleByCategoryId($categoryIds, $pager);
            foreach($articleInfo as $key => $val) {
                $articleInfo[$key]['CategoryName'] = $category[$val['CategoryId']]['CategoryName'];
            }
            $this->assign('pid', $pid);
            $this->assign('articleInfo', $articleInfo);
            $this->assign('pager', $pager);
        }
        $this->display();
    }

}